<template>
    <Modal
            width="800"
            v-model="visible"
            :title="title"
            :key="key"
    >
        <div style="width: 80%;padding-left: 10%;padding-right: 10%" >
            <Spin size="large" fix v-if="Loading"></Spin>
            <Form :label-width="130" :disabled="disableSubmit" ref="formValidate" :model="formValidate"
                  :rules="ruleValidate">
                <Form-item label="名称:" prop="entityName">
                    <Input v-model="formValidate.entityName" placeholder="请输入名称"/>
                </Form-item>
                <Form-item label="描述:" prop="entityDesc">
                    <Input v-model="formValidate.entityDesc" placeholder="请输入描述"/>
                </Form-item>
                <Form-item label="标识:" prop="entityIdentify">
                    <Input v-model="formValidate.entityIdentify" placeholder="请输入标识"/>
                </Form-item>
                <Form-item label="包路径" prop="pkgName">
                    <Input v-model="formValidate.pkgName" placeholder="请输入包路径"/>
                </Form-item>
                <Form-item label="备注">
                    <Input v-model="formValidate.remarks" placeholder="请输入备注"/>
                </Form-item>
            </Form>
        </div>
        <div slot="footer">
            <Button @click="cancel">取消</Button>
            <template v-if="!disableSubmit">
                <Button type="primary" @click="ok">确定</Button>
            </template>
        </div>
    </Modal>
</template>

<script>
    import {getAction, postAction} from '@/api/request'

    export default {
        data() {
            return {
                modal1: false,
                title: "",
                visible: false,
                key: "",
                disableSubmit: false,
                Loading: false,
                formValidate: {
                    entityName: '',
                    entityDesc: '',
                    entityIdentify: '',
                    pkgName: ''
                },
                ruleValidate: {
                    entityName: [
                        {required: true, message: '名称不能为空', trigger: 'blur'}
                    ],
                    entityDesc: [
                        {required: true, message: '描述不能为空', trigger: 'blur'}
                    ],
                    entityIdentify: [
                        {required: true, message: '标识不能为空', trigger: 'blur'}
                    ],
                    pkgName: [
                        {required: true, message: '包路径不能为空', trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            ok() {
                var that = this;
                this.$refs['formValidate'].validate((valid) => {
                    if (valid) {
                        that.submitFrom();
                    }
                })
            },
            submitFrom() {
                var that = this;
                that.Loading = true;
                postAction("/api/ac/subsistence/RuleEntityService/insert", this.formValidate).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$emit('ok');
                        this.visible = false;
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            },
            cancel() {
                this.visible = false;
            },
            add() {
                this.visible = true
                this.formValidate = Object.assign({}, {});
            },
            edit(row) {
                this.visible = true
                this.formValidate = Object.assign({}, row);
            },
        }
    }
</script>

<style scoped>

</style>